package com.ruoyi.project.zerocarbon.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.framework.security.service.TokenService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.project.zerocarbon.auth.APIValidateUtil;
import com.ruoyi.project.zerocarbon.domain.Declaration;
import com.ruoyi.project.zerocarbon.domain.DeclareExpert;
import com.ruoyi.project.zerocarbon.domain.DeclareReporter;
import com.ruoyi.project.zerocarbon.domain.UserRegion;
import com.ruoyi.project.zerocarbon.domain.vo.DeclarationAuditVo;
import com.ruoyi.project.zerocarbon.domain.vo.DeclarationCenterAuditVo;
import com.ruoyi.project.zerocarbon.domain.vo.DeclarationVo;
import com.ruoyi.project.zerocarbon.mapper.DeclarationMapper;
import com.ruoyi.project.zerocarbon.mapper.DeclareExpertMapper;
import com.ruoyi.project.zerocarbon.mapper.DeclareJudgeMapper;
import com.ruoyi.project.zerocarbon.mapper.UserRegionMapper;
import com.ruoyi.project.zerocarbon.service.IDeclarationService;
import com.ruoyi.project.zerocarbon.service.IDeclareReporterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.stream.Collectors;

import static com.ruoyi.common.utils.file.FileUtils.percentEncode;

/**
 * @类名: AuditController
 * @描述:
 * @作者:
 * @日期: 2021/6/26 15:07
 */
@Slf4j
@Api("管理")
@RequestMapping("/audit")
@RestController
public class AuditController extends BaseController {

    @Autowired
    private UserRegionMapper userRegionMapper;
    @Autowired
    private DeclarationMapper declarationMapper;
    @Autowired
    private DeclareJudgeMapper declareJudgeMapper;
    @Autowired
    private DeclareExpertMapper declareExpertMapper;
    @Autowired
    private IDeclarationService declarationService;
    @Autowired
    private IDeclareReporterService declareReporterService;
    @Autowired
    private SysUserMapper sysUserMapper;

    @Autowired
    private TokenService tokenService;
    @Value("${declaration.auth.accessKeyId}")
    private String accessKeyId;
    @Value("${declaration.auth.accessKeySecret}")
    private String accessKeySecret;

    /**
     * 地区列表，如果是全国，则前端显示全部地区
     *
     * @param userId
     * @return
     */
    @GetMapping("/decoration/region/list")
    public AjaxResult regionList(Long userId) {
        //每个用户只能提交一次
        Assert.notNull(userId);
        List<UserRegion> userRegions = userRegionMapper.selectByUserId(userId);
        if (CollectionUtils.isNotEmpty(userRegions))
            return AjaxResult.success(userRegions.stream().map(UserRegion::getRegion).collect(Collectors.toList()));
        return AjaxResult.success();
    }

    /**
     * 团中央地区接口，包含审核状态
     *
     * @param
     * @return
     */
    @ApiOperation("团中央地区接口，包含审核状态")
    @GetMapping("/decoration/regionStatus/list")
    public AjaxResult regionStatusList(Long userId,Integer managementType) {
        //每个用户只能提交一次
        //        RegionStatusVo
        List<DeclarationAuditVo> regionCheckStatus = new ArrayList<>();
        String[] regions = {"北京", "天津", "河北", "山西", "内蒙古", "辽宁",
                    "吉林",
                    "黑龙江",
                    "上海",
                    "江苏",
                    "浙江",
                    "安徽",
                    "福建",
                    "江西",
                    "山东",
                    "河南",
                    "湖北",
                    "湖南",
                    "广东",
                    "广西",
                    "海南",
                    "重庆市",
                    "四川",
                    "贵州",
                    "云南",
                    "西藏",
                    "陕西",
                    "甘肃",
                    "青海",
                    "宁夏",
                    "新疆",
                    "新疆兵团",
                    "其他"};
        for (String region:regions){
            Integer status = declarationMapper.getRegionCheckStatusByProvince(managementType, region);
            DeclarationAuditVo vo = new DeclarationAuditVo();
            vo.setAuditStatus(status);
            vo.setProvince(region);
            regionCheckStatus.add(vo);
        }
        return AjaxResult.success(regionCheckStatus);
    }

    /**
     * 审核接口
     */
    @PostMapping("/decoration/status/save")
    public AjaxResult auditDecoration(@Validated @RequestBody DeclarationAuditVo auditVo) {
        Assert.notNull(auditVo.getDeclarationId());
        Assert.notNull(auditVo.getSaveType());

        return AjaxResult.success(declarationService.auditDecoration(auditVo));
    }

    /**
     * 审核接口
     */
    @ApiOperation("团中央审核列表下载图片接口,根据上报人手机号，区分类型")
    @GetMapping("/decoration/province/picList")
    public AjaxResult auditDecoration(String contactNumber,Integer managementType) {
        Assert.notNull(contactNumber);
        Assert.notNull(managementType,"项目类型不能为空");
        DeclareReporter declareReporter = new DeclareReporter();
        declareReporter.setContactNumber(contactNumber);
        declareReporter.setManagementType(managementType);
        List<DeclareReporter> declareReporters = declareReporterService.selectDeclareReporterList(declareReporter);
        List<String> picUrls = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(declareReporters)){
            declareReporters = declareReporters.stream().sorted(Comparator.comparing(DeclareReporter::getId).reversed()).collect(Collectors.toList());
            String picture = declareReporters.get(declareReporters.size() - 1).getPicture();
            if (!StringUtils.isEmpty(picture)){
                picUrls.add(picture);
            }
        }
        return AjaxResult.success(picUrls);
    }

    /**
     * 修改【请填写功能名称】
     */
    @ApiOperation("更新(根据id)")
    @PutMapping("/decoration/management/edit")
    public AjaxResult edit(@RequestBody Declaration declaration) {
        Assert.notNull(declaration.getId());
        if (!StringUtils.isEmpty(declaration.getRecommendNum())){
            DeclarationVo declarationVo = new DeclarationVo();
            declarationVo.setRecommendNum(declaration.getRecommendNum());
//            if (!StringUtils.isEmpty(declaration.getProvince())){
//                declarationVo.setRegion(declaration.getProvince());
//            } else {
            Declaration history = declarationMapper.selectDeclarationById(declaration.getId());
            declarationVo.setRegion(history.getProvince());
            declarationVo.setManagementType(history.getManagementType());
//            }
            List<Declaration> declarations = declarationMapper.selectDeclarationList(declarationVo);
            if (StringUtils.isNotEmpty(declarations)){
//                throw new CustomException("同一省份推荐号不可重复！");
                return AjaxResult.error("同一省份推荐号不可重复！");
            }
        }
        declaration.setUpdateTime(new Date());
        return toAjax(declarationService.updateDeclaration(declaration));
    }

    /**
     * 项目管理列表
     *
     * @param declarationVo
     * @return
     */
    @ApiOperation("项目管理列表")
    @PostMapping("/decoration/management/list")
    public TableDataInfo managementList(@Validated @RequestBody DeclarationVo declarationVo) {
        //每个用户只能提交一次
        //        startPage();
        Integer pageNum = declarationVo.getPageNum() != null ? declarationVo.getPageNum() : 1;
        Integer pageSize = declarationVo.getPageSize() != null ? declarationVo.getPageSize() : 20;
        String orderBy = "region_serial desc";
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            PageHelper.startPage(pageNum, pageSize, orderBy);
        }

        if (StringUtils.isEmpty(declarationVo.getRegion())) {
            Long userId = null;
            if (declarationVo.getUserId() != null) {
                userId = declarationVo.getUserId();
            } else {
                LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
                userId = loginUser.getUser().getUserId();
            }
            if (userId != null) {
                List<UserRegion> userRegions = userRegionMapper.selectByUserId(userId);
                if (CollectionUtils.isNotEmpty(userRegions)) {
                    if (userRegions.get(0).getRegion().equals("全国")) {
                        declarationVo.setRegion("全国");
                    } else {
                        declarationVo.setRegion(userRegions.get(0).getRegion());
                    }
                } else {
                    return getDataTable(new ArrayList<>());
                }
            }
        }
        if (declarationVo.getSaveType() == null && CollectionUtils.isEmpty(declarationVo.getSaveTypeList())) {
            declarationVo.setSaveTypeList(Arrays.asList(1, 2, 3, 4, 5));
        }
        List<Declaration> list = declarationService.getDecorationList(declarationVo);
        //0：待提交（草稿）；1：已提交; 2:已报名（APP预约）
        return getDataTable(list);
    }

    /**
     * 项目报名列表
     *
     * @param declarationVo
     * @return
     */
    @ApiOperation("项目报名列表,待审核11、淘汰12、通过13;auditStatus>=13都是通过")
    @PostMapping("/decoration/signUp/list")
    public TableDataInfo signUpList(@Validated @RequestBody DeclarationVo declarationVo) {
        Integer pageNum = declarationVo.getPageNum() != null ? declarationVo.getPageNum() : 1;
        Integer pageSize = declarationVo.getPageSize() != null ? declarationVo.getPageSize() : 20;
        String orderBy = "region_serial desc";
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            PageHelper.startPage(pageNum, pageSize, orderBy);
        }
        declarationVo.setSaveType(1);
        if (declarationVo.getAuditStatus() == null) {

        } else if (declarationVo.getAuditStatus() == 13) {
            declarationVo.setAuditStatusList(Arrays.asList(13, 21, 22, 23, 24, 25));
        }
        List<Declaration> list = declarationService.getDecorationList(declarationVo);
        //0：待提交（草稿）；1：已提交; 2:已报名（APP预约）
        return getDataTable(list);
    }


    /**
     * 上报列表
     *
     * @param declarationVo
     * @return
     */
    @ApiOperation("上报列表")
    @PostMapping("/decoration/report/list")
    public TableDataInfo reportList(@Validated @RequestBody DeclarationVo declarationVo) {
        Integer pageNum = declarationVo.getPageNum() != null ? declarationVo.getPageNum() : 1;
        Integer pageSize = declarationVo.getPageSize() != null ? declarationVo.getPageSize() : 20;
        String orderBy = "region_serial desc";
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            PageHelper.startPage(pageNum, pageSize, orderBy);
        }

        if (declarationVo.getAuditStatus() == null || declarationVo.getAuditStatus() < 13) {
            declarationVo.setAuditStatusList(Arrays.asList(13, 21, 22, 23, 24, 25));
        }
        List<Declaration> list = declarationService.getDecorationList(declarationVo);
        //0：待提交（草稿）；1：已提交; 2:已报名（APP预约）
        return getDataTable(list);
    }

    /**
     * 新增【请填写功能名称】
     */
    @ApiOperation("上报人提交")
    @PostMapping("/decoration/report/add")
    public AjaxResult addReporter(@RequestBody DeclareReporter declareReporter) {
        //创意作品上报数量不超过100
        if (declareReporter.getDeclarationId() != null) {
            Long declarationId = declareReporter.getDeclarationId();
            Declaration declarationById = declarationMapper.selectDeclarationById(declarationId);
            if (declarationById.getManagementType() == 3) {
                Integer count = declarationMapper.countReporterByManagementTypeAndStatus(declarationById.getManagementType(), declarationById.getProvince());
                if (count != null && count > 100) {
                    return AjaxResult.error("创意作品同一省份上报数量不超过100");
                }
            }
            Declaration declaration = new Declaration();
            declaration.setId(declarationId);
            declaration.setAuditStatus(21);
            declaration.setReporter(declareReporter.getReporter());
            declaration.setUpdateTime(new Date());
            declarationService.updateDeclaration(declaration);
            DeclareReporter reporter = declareReporterService.selectDeclareReporterByDeclarationId(declarationId);
            if (reporter != null) {
                reporter.setPicture(declareReporter.getPicture());
                reporter.setContactNumber(declareReporter.getContactNumber());
                reporter.setReporter(declareReporter.getReporter());
                reporter.setManagementType(declarationById.getManagementType());
                declareReporterService.updateDeclareReporter(reporter);
            } else {
                declareReporter.setManagementType(declarationById.getManagementType());
                declareReporterService.insertDeclareReporter(declareReporter);
            }
            return AjaxResult.success();
        }
        if (CollectionUtils.isNotEmpty(declareReporter.getDeclarationIdList())) {
            for (int i = 0; i < declareReporter.getDeclarationIdList().size(); i++) {
                Long declarationId = declareReporter.getDeclarationIdList().get(i);
                Declaration declarationById = declarationMapper.selectDeclarationById(declarationId);
                if (declarationById.getManagementType() == 3) {
                    Integer count = declarationMapper.countReporterByManagementTypeAndStatus(declarationById.getManagementType(), declarationById.getProvince());
                    if (count != null && count > 100) {
                        return AjaxResult.error("创意作品同一省份上报数量不超过100");
                    }
                }
                DeclareReporter reporter = declareReporterService.selectDeclareReporterByDeclarationId(declarationId);
                if (reporter != null) {
                    reporter.setPicture(declareReporter.getPicture());
                    reporter.setContactNumber(declareReporter.getContactNumber());
                    reporter.setReporter(declareReporter.getReporter());
                    reporter.setManagementType(declarationById.getManagementType());
                    declareReporterService.updateDeclareReporter(reporter);
                } else {
                    declareReporter.setManagementType(declarationById.getManagementType());
                    declareReporterService.insertDeclareReporter(declareReporter);
                }
                Declaration declaration = new Declaration();
                declaration.setId(declarationId);
                declaration.setAuditStatus(21);
                declaration.setReporter(declareReporter.getReporter());
                declaration.setUpdateTime(new Date());
                declarationService.updateDeclaration(declaration);
            }
        }
        return AjaxResult.success();
    }

    /**
     * 项目报名列表
     *
     * @param declarationVo
     * @return
     */
    @ApiOperation("分配列表")
    @PostMapping("/decoration/distribution/list")
    public TableDataInfo distributionList(@Validated @RequestBody DeclarationVo declarationVo) {
        Integer pageNum = declarationVo.getPageNum() != null ? declarationVo.getPageNum() : 1;
        Integer pageSize = declarationVo.getPageSize() != null ? declarationVo.getPageSize() : 20;
        String orderBy = "region_serial desc";
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            PageHelper.startPage(pageNum, pageSize, orderBy);
        }

        if (declarationVo.getAuditStatus() == null || declarationVo.getAuditStatus() < 21) {
            declarationVo.setAuditStatus(24);
        }
        List<Declaration> list = declarationService.getDecorationList(declarationVo);
        for(Declaration declaration:list){
            DeclareExpert declareExpert = declareExpertMapper.selectDeclareExpertByDeclarationId(declaration.getId());
            if (declareExpert != null){
                declaration.setGroupName(declareExpert.getGroupName());
            }
        }
        return getDataTable(list);
    }


    /**
     * 项目报名列表
     *
     * @param declarationVo
     * @return
     */
    @ApiOperation("排名列表,评审委员会")
    @PostMapping("/decoration/ranking/list")
    public TableDataInfo rankingList(@Validated @RequestBody DeclarationVo declarationVo) {
        Integer pageNum = declarationVo.getPageNum() != null ? declarationVo.getPageNum() : 1;
        Integer pageSize = declarationVo.getPageSize() != null ? declarationVo.getPageSize() : 20;
        String orderBy = "dr.score desc";
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            PageHelper.startPage(pageNum, pageSize, orderBy);
        }

        if (declarationVo.getAuditStatus() == null || declarationVo.getAuditStatus() < 23) {
            declarationVo.setAuditStatus(24);
        }
        declarationVo.setDistributionStatus(1);
        List<Declaration> list = declarationService.getRankingDecorationList(declarationVo);
        //0：待提交（草稿）；1：已提交; 2:已报名（APP预约）
        return getDataTable(list);
    }

    @ApiOperation("小组项目列表，每页5条")
    @PostMapping("/decoration/group/list")
    public TableDataInfo groupList(@Validated @RequestBody DeclarationVo declarationVo) {
        Integer pageNum = declarationVo.getPageNum() != null ? declarationVo.getPageNum() : 1;
        Integer pageSize = declarationVo.getPageSize() != null ? declarationVo.getPageSize() : 100;
        String orderBy = "d.id desc";
        String groupName = declarationVo.getGroupName();
        Assert.notNull(groupName,"groupName cannot be null");
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            PageHelper.startPage(pageNum, pageSize, orderBy);
        }
        List<Declaration> list = declarationService.getGroupDecorationList(declarationVo);
        //0：待提交（草稿）；1：已提交; 2:已报名（APP预约）
        return getDataTable(list);
    }

    /**
     * 评分列表
     *
     * @param declarationVo
     * @return
     */
    @ApiOperation("评分列表")
    @PostMapping("/decoration/judge/list")
    public TableDataInfo judgeList(@Validated @RequestBody DeclarationVo declarationVo) {
        List<Declaration> list = new ArrayList<>();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String groupName = sysUserMapper.selectRemarkByUserId(loginUser.getUser().getUserId());
        declarationVo.setGroupName(groupName);
        if (StringUtils.isEmpty(groupName)){
            return getDataTable(list);
        }

        declarationVo.setDistributionStatus(1);
        if (declarationVo.getAuditStatus() == null || declarationVo.getAuditStatus() < 23) {
            declarationVo.setAuditStatus(24);
        }
        Integer pageNum = declarationVo.getPageNum() != null ? declarationVo.getPageNum() : 1;
        Integer pageSize = declarationVo.getPageSize() != null ? declarationVo.getPageSize() : 500;
        //        String orderBy = "id desc";
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            PageHelper.startPage(pageNum, pageSize);
        }
        List<Declaration> groupDecorationList;
        if (declarationVo.getJudgeStatus() != null && declarationVo.getJudgeStatus() ==0){
            declarationVo.setUserName(loginUser.getUser().getUserName());
            groupDecorationList = declarationMapper.getGroupDecorationListAndNoJudgeStatus(declarationVo);
        }else if (declarationVo.getJudgeStatus() != null && declarationVo.getJudgeStatus() > 0){
            declarationVo.setUserName(loginUser.getUser().getUserName());
            groupDecorationList = declarationMapper.getGroupDecorationListAndJudgeStatus(declarationVo);
        }else {
            groupDecorationList = declarationMapper.getGroupDecorationList(declarationVo);
        }
        list = declarationService.getJudgeDecorationListByVoList(groupDecorationList,declarationVo.getJudgeStatus(),loginUser.getUser().getUserName());

        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(groupDecorationList).getTotal());
        return rspData;
    }

    /**
     * decoration
     *
     * @param declarationVo
     * @return
     */
    @ApiOperation("审核列表")
    @PostMapping("/decoration/check/list")
    public TableDataInfo checkList(@Validated @RequestBody DeclarationVo declarationVo) {
        Integer pageNum = declarationVo.getPageNum() != null ? declarationVo.getPageNum() : 1;
        Integer pageSize = declarationVo.getPageSize() != null ? declarationVo.getPageSize() : 50;
        String orderBy = "reporter desc";
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            PageHelper.startPage(pageNum, pageSize, orderBy);
        }

        if (declarationVo.getAuditStatus() == null || declarationVo.getAuditStatus() < 21) {
            declarationVo.setAuditStatusList(Arrays.asList(21, 24));
        }
        if (StringUtils.isEmpty(declarationVo.getRegion())) {
            declarationVo.setRegion("全国");
        }
        List<Declaration> list = declarationService.getDecorationList(declarationVo);
        if (CollectionUtils.isNotEmpty(list)) {
            for (Declaration declaration : list) {
                DeclareReporter reporter = declareReporterService.selectDeclareReporterByDeclarationId(declaration.getId());
                if (reporter != null) {
                    declaration.setReporter(reporter.getReporter());
                    declaration.setReporterContactNumber(reporter.getContactNumber());
                }
            }
        }
        //0：待提交（草稿）；1：已提交; 2:已报名（APP预约）
        return getDataTable(list);
    }

    private String mailUrl = "https://third.api.zyh365.com/api/comm/sendMessage.do";

    @ApiOperation("审核,通过或驳回（批量）")
    @PostMapping("/decoration/check/edit")
    public AjaxResult editBatch(@Validated @RequestBody DeclarationAuditVo declarationAuditVo) {
        for (Long id : declarationAuditVo.getDeclarationIdList()) {
            Declaration declaration = new Declaration();
            declaration.setId(id);
            declaration.setAuditStatus(declarationAuditVo.getAuditStatus());
            if (StringUtils.isNotEmpty(declarationAuditVo.getAuditComment())){

            }
            declaration.setAuditComment(declarationAuditVo.getAuditComment());
            declaration.setCenterComment(declarationAuditVo.getCenterComment());
            declaration.setUpdateTime(new Date());
            declarationService.updateDeclaration(declaration);
        }

        return AjaxResult.success();
    }

    public static void main(String[] args) {
        String mailUrl = "https://third.api.zyh365.com/api/comm/sendMessage.do";
        String message = "您好，您所提交的零碳科技大展评审资料已通过。";
        String accessKeySecret = "a333fe38ecc34de2b4dc0b7704a02ef5";
        String phone = "18611432234";
        Map<String,String> mapv=new HashMap<String, String>();
        mapv.put("AccessKeyId", "a0f215286d96449baeac25dc179a714a");
        mapv.put("tel", phone);
        mapv.put("message", message);
        String response = null;
        try {
            String key = new APIValidateUtil().computeSignature(mapv, accessKeySecret);
            String rspStr = "tel="+phone+"&message="+message+"&AccessKeyId="+mapv.get("AccessKeyId")+"&Signature="+percentEncode(key);
            response = HttpUtils.sendPost(mailUrl, rspStr);
            log.info("发送短信验证码 response: {}",response);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void sendMessage(String phone,String message){
        Map<String,String> mapv=new HashMap<String, String>();
        mapv.put("AccessKeyId", accessKeyId);
        mapv.put("tel", phone);
        mapv.put("message", message);
        String response = null;
        try {
            String key = new APIValidateUtil().computeSignature(mapv, accessKeySecret);
            String rspStr = "tel="+phone+"&message="+message+"&AccessKeyId="+mapv.get("AccessKeyId")+"&Signature="+percentEncode(key);
            response = HttpUtils.sendPost(mailUrl, rspStr);
            log.info("发送团中央审核短信 phone：{}，response: {}",phone,response);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ApiOperation("团中央审核提交人")
    @PostMapping("/decoration/centerCheck/edit")
    public AjaxResult centerCheck(@Validated @RequestBody DeclarationCenterAuditVo declarationAuditVo) {
        Assert.notNull(declarationAuditVo.getReporter());
        Assert.notNull(declarationAuditVo.getManagementType());
        DeclarationVo declaration = new DeclarationVo();
        declaration.setReporter(declarationAuditVo.getReporter());
        declaration.setManagementType(declarationAuditVo.getManagementType());
        List<Declaration> declarations = declarationMapper.selectDeclarationList(declaration);
        for (Declaration model:declarations){
            model.setAuditStatus(declarationAuditVo.getAuditStatus());
            model.setCenterComment(declarationAuditVo.getCenterComment());
            model.setUpdateTime(new Date());
            declarationService.updateDeclaration(model);
        }
        DeclareReporter declareReporter = new DeclareReporter();
        declareReporter.setManagementType(declarationAuditVo.getManagementType());
        declareReporter.setReporter(declarationAuditVo.getReporter());
        List<DeclareReporter> declareReporters = declareReporterService.selectDeclareReporterList(declareReporter);
        if (declarationAuditVo.getAuditStatus() == 25){
            //清除上报人数据

            sendMessage(declareReporters.get(declareReporters.size()-1).getContactNumber(),"您好，您所提交的零碳科技大展评审资料已被系统驳回，请登录评审系统查看修改。");
        }else {
            sendMessage(declareReporters.get(declareReporters.size()-1).getContactNumber(),"您好，您所提交的零碳科技大展评审资料已通过。");
        }
        return AjaxResult.success();
    }

    /**
     * 查看申报
     *
     * @param declarationId
     * @return
     */
    @ApiOperation("详情")
    @GetMapping("/decoration/detail")
    public AjaxResult detail(Long declarationId) {
        Assert.notNull(declarationId);
        return AjaxResult.success(declarationService.getDecorationDTO(declarationId));
    }

}
